﻿using BaseGrpcEFCore.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace BaseGrpcEFCore.Extensions
{
    public static class DbContexExtensions
    {
        public static IServiceCollection AddMysqlDbContext(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddEntityFrameworkMySql();
            /*所有GRPC服务都可以集中这里映射*/
            services.AddDbContext<BaseDbContext>(optionsBuilder =>
            {
                var conf = configuration.GetConnectionString("Default");
                optionsBuilder.UseMySql(conf, ServerVersion.AutoDetect(conf));
            });
            return services;
        }
    }
}
